<?php
require_once("conn.php");
if( isset ( $_POST['reg'] )) {
	$q =" SELECT nick FROM players WHERE nick='" . $_POST['nick'] . "'";
	$result = mysql_query( $q );
	$num = mysql_num_rows( $result );
	if($num > 0) {
		$failed = true;
		echo "The nickname already exists<br />";
	}
	if($_POST['pass'] !== $_POST['passcheck']) {
		$failed = true;
		echo "The passswords doesn't match<br />";
	}
	if( !isset ( $failed )) {
	$q = "INSERT INTO players SET nick='" . $_POST['nick'] . "', pass='" . md5($_POST['pass']) . "'";
	@mysql_query( $q ) or die("Something went wrong");
	echo "Your player setup is finished";
	}
		
}
echo '
<form action="register.php" method="post">
<table>
<tr>
<td align="right">Your nickname</td>
<td><input type="text" name="nick"></td>
</tr>
<tr>
<td align="right">Password</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>Password again</td>
<td><input type="password" name="passcheck"></td>
</tr>
<tr>
<td>
<input type="submit" name="reg" value="Done">
</td>
</tr>
</table>
</form>
';
?>